function editSubmenuPage(node_id,menu_title)
{
	$('edit_menu_section').style.display = "none";
	callAJAX('xoad_handler','editSubmenuPage', $H({node_id: node_id, menu_title: menu_title}),editSubmenuPage_callback);		
}

function editSubmenuPage_callback(result)
{
	if (result=="OK")
	{
		$('edit_page_section').style.display="";
	}
	else
	{
		alert(result);
	}
}

function cancelEditPage()
{
	$('edit_page_section').style.display="none";	
}

function addSubmenu()
{
	$('edit_page_section').style.display = 'none';
	$('edit_form_title').innerHTML = "Add submenu";
	$('edit_menu_section').style.display = "";
	$('menu_id').value = "";
	$('menu_order').value = "";
	$('menu_title').value = "";
	$('edit_menu_save').disabled = false;
}

function editSubmenu(menu_id)
{
	$('edit_page_section').style.display = 'none';
	$('edit_form_title').innerHTML = "Edit submenu";
	$('edit_menu_section').style.display = "";
	$('menu_id').value = menu_id;
	row_id = 'menu_row'+menu_id;
	td_array = $(row_id).getElementsByTagName('td');
	$('menu_order').value = td_array[0].innerHTML;
	divSubMenuTitleId = ("submenu_title_" + menu_id.toString());
	$('menu_title').value = $(divSubMenuTitleId).innerHTML;
//	$('menu_hide').value  = td_array[2].innerHTML;
	$('edit_menu_save').disabled = false;
}

function saveSubmenu()
{
	if (validateSubMenu())
	{
	    alert(validateSubMenu());
	}
	else
	{
	   callAJAX('xoad_handler','saveSubmenu', $H({form: xoad.html.exportForm('edit_menu')}), saveSubmenu_callback);	
	}
}

function saveSubmenu_callback(result)
{
	if (result=="OK")
	{
		$('edit_menu_section').style.display = "none";
	}
	else
	{
		alert(result);
	}
}

function deleteSubmenu(menu_id,menu_title)
{
	var sure = confirm('Do you really want to delete "' + menu_title + '" and its page content?');
	if (sure)
	{
		callAJAX('xoad_handler','deleteSubmenu', $H({menu_id: menu_id,menu_parent_id: $('menu_parent_id').value }), deleteSubmenu_callback);	
	}
}

function deleteSubmenu_callback(result)
{
    if (result!="OK")
    {
        alert(result);
    }
}

function addNews()
{
    callAJAX('xoad_handler','addNews', $H({}),addNews_callback);
}

function addNews_callback(result)
{
    if (result=="OK")
	{
		$('edit_news_section').style.display="";
	}
	else
	{
		alert(result);
	}
}

function editNews(news_id,news_title)
{
    callAJAX('xoad_handler','editNews', $H({news_id: news_id, news_title: news_title}),editNews_callback);
}

function editNews_callback(result)
{
    if (result=="OK")
	{
		$('edit_news_section').style.display="";
	}
	else
	{
		alert(result);
	}
}

function deleteNews(news_id,news_title)
{
	var sure = confirm('Do you really want to delete "' + news_title + '" and its content?');
	if (sure)
	{
	    $('edit_news_section').style.display="none";
		callAJAX('xoad_handler','deleteNews', $H({news_id: news_id}), deleteNews_callback);	
	}
}

function deleteNews_callback(result)
{
    if (result!="OK")
    {
        alert(result);
    }
}

function toggleNewsPublish(news_id,publish_value)
{
    callAJAX('xoad_handler','toggleNewsPublish', $H({news_id: news_id,publish_value: publish_value}), toggleNewsPublish_callback);	
}

function toggleNewsPublish_callback(result)
{
    if (result!="OK")
    {
        alert(result);
    }
}

function cancelEditNews()
{
	$('edit_news_section').style.display="none";	
}

function editAdmissionPage(pro_menu_id,admission_type,admission_title, partner_id)
{
    callAJAX('xoad_handler','loadAdmissionContent', $H({menu_id: pro_menu_id,admission: admission_type, admission_title:admission_title, partner_id: partner_id}), editAdmissionPage_callback);
}

function addPartnerAdmission()
{
    menu_id = $('pro_title').value;
    partner = $('pro_partner').value;
    callAJAX('xoad_handler','addPartnerAdmission', $H({menu_id: menu_id, partner_id: partner}), addPartnerAdmission_callback);	
}

function addPartnerAdmission_callback(result)
{
    if (result!="OK")
    {
        alert(result);
    }
}

function editAdmissionPage_callback(result)
{
    if (result=="OK")
    {
        $('edit_admission_section').style.display="";
    }
    else
    {
        alert(result);
    }
}

function deleteAdmissionSubpage(pro_id,type)
{
    var sure = confirm('Are you sure to delete subpage (content will be loss)?');
	if (sure)
	{	     
	   callAJAX("xoad_handler","deleteAdmissionSubpage",$H({pro_id: pro_id,type:type}),deleteAdmissionSubpage_callback);
	}    
}

function deleteAdmissionSubpage_callback(result)
{
    if (result!="OK")
    {
        alert(result);
    }
}

function deleteProgramme(pro_title,partner_title,pro_id)
{
    var sure = confirm('Are you sure to delete program ' + pro_title + ' provided by ' + partner_title + ' (content will be loss)?');
	if (sure)
	{
	     $('edit_admission_section').style.display="none";
	     callAJAX("xoad_handler","deleteProgramme",$H({pro_id: pro_id}),deleteProgramme_callback);
	}
}

function deleteProgramme_callback(result)
{
    if (result!="OK")
    {
        alert(result);
    }
}

function cancelEditAdmission()
{
    var sure = confirm('Are you sure to cancel (content will leave no change)?');
	if (sure)
	{
	     $('edit_admission_section').style.display="none";
	}
}

function addProfilePage()
{
    profile_type = $('current_profile_type').value;
    callAJAX('xoad_handler','editProfilePage', $H({profile_type: profile_type}), addProfilePage_callback);
}

function addProfilePage_callback(result)
{
    if (result=="OK")
    {
        $('edit_profile_section').style.display="";
    }
    else
    {
        alert(result);
    }
}

function editProfile(profile_id)
{
    profile_type = $('current_profile_type').value;
    callAJAX('xoad_handler','editProfilePage', $H({profile_id: profile_id,profile_type: profile_type}), editProfilePage_callback);	
}

function editProfilePage_callback(result)
{
    if (result == "OK")
    {
        $('edit_profile_section').style.display="";
    }
    else
    {
        alert(result);
    }
}

function deleteProfile(profile_id,profile_title)
{
    var sure = confirm('Are you sure to delete' + profile_title + ' (content will be lost)?');
	if (sure) 
	{
        $('edit_profile_section').style.display="none";
        profile_type = $('current_profile_type').value;
        callAJAX('xoad_handler','deleteProfile', $H({profile_id: profile_id,profile_type: profile_type}), deleteProfile_callback);	
	}    
}

function deleteProfile_callback(result)
{
    if (result != "OK")
    {
        alert(result);
    }
}

function cancelEditProfile()
{
    var sure = confirm('Are you sure to cancel (content will leave no change)?');
	if (sure)
	{
	     $('edit_profile_section').style.display="none";
	}
}

function copyURL()
{
	$('return_url').value = $('current_url').value;
}

function copyType()
{
    $('return_url').value = $('current_url').value;
    $('profile_type').value = $('current_profile_type').value;
}

function toggleGroupHide(group_id,hide_value)
{
    callAJAX('xoad_handler','toggleGroupHide', $H({group_id: group_id,hide_value: hide_value}), toggleGroupHide_callback);
}

function toggleGroupHide_callback(result)
{
    if (result!="OK")
    {
        alert(result);
    }
}

function saveGroup()
{
    callAJAX('xoad_handler','saveGroup',$H({form: xoad.html.exportForm('edit_group_form')}),saveGroup_callback);
}

function saveGroup_callback(result)
{
    if (result=="OK")
    {
        $('edit_group_section').style.display="none";
    }
    else
    {
        alert(result);
    }
}

function deleteGroup(group_id)
{
    var sure = confirm('Are you sure to delete this group?');
	if (sure) 
	{
        $('edit_group_section').style.display="none";
        callAJAX('xoad_handler','deleteGroup', $H({group_id: group_id}), deleteGroup_callback);	
	} 
}

function deleteGroup_callback(result)
{
    if (result !="OK")
    {
        alert(result);
    }
}

function editGroupQuestion(group_id)
{
    callAJAX('xoad_handler','editGroupQuestion',$H({group_id:group_id}),editGroupQuestion_callback);
}

function editGroupQuestion_callback(result)
{
    if (result=="OK")
    {
        $('group_question_list').style.display="";
    }
    else
    {
        alert(result);
    }
}

function editGroupQuestionOrder(faq_id,order)
{
    $('question_order').value = order;
    $('group_question_id').value = faq_id;
    $('group_question_order_section').style.display = "";
}

function saveGroupQuestionOrder()
{
    callAJAX('xoad_handler','saveGroupQuestionOrder',$H({faq_id: $('group_question_id').value,group_id:$('group_id').value, question_order: $('question_order').value}),saveGroupQuestionOrder_callback);    
}

function saveGroupQuestionOrder_callback(result)
{
    if (result=="OK")
    {
        $('group_question_order_section').style.display="none";
    }
    else
    {
        alert(result);
    }
}

function deleteGroupQuestion(faq_id)
{
    callAJAX('xoad_handler','deleteGroupQuestion',$H({faq_id:faq_id, group_id:$('group_id').value}),deleteGroupQuestion_callback);
}

function deleteGroupQuestion_callback(faq_id)
{
    if (result !="OK")
    {
        alert(result);
    }
}

function cancelGroup()
{
    $('edit_group_section').style.display="none";
}

function editGroup(group_id)
{
    callAJAX('xoad_handler','editGroup',$H({group_id:group_id}),editGroup_callback);
}

function editGroup_callback(result)
{
    if (result=="OK")
    {
        $('edit_group_section').style.display="";
    }
    else
    {
        alert(result);
    }
}

function addGroup()
{
    callAJAX('xoad_handler','addGroup',$H({}),addGroup_callback);
}

function addGroup_callback(result)
{
    if (result=="OK")
    {
        $('edit_group_section').style.display="";
    }
    else
    {
        alert(result);
    }
}

function addQuestionToGroup(faq_id,faq_order)
{
    callAJAX('xoad_handler','addQuestionToGroup',$H({group_id:$('group_id').value, faq_id:faq_id, faq_order:faq_order}),addQuestionToGroup_callback);
}

function addQuestionToGroup_callback(result)
{
    if (result!="OK")
    {
        alert(result);
    }
}

function editFaq(faq_id)
{
    callAJAX('xoad_handler','editFaq', $H({faq_id: faq_id}),editFaq_callback);
}

function editFaq_callback(result)
{
    if (result=="OK")
	{
		$('edit_faq_section').style.display="";
	}
	else
	{
		alert(result);
	}
}

function cancelFaq()
{
    $('edit_faq_section').style.display="none";
}

function saveFaq()
{
    callAJAX('xoad_handler','saveFaq', $H({form: xoad.html.exportForm('faq_edit_form')}),saveFaq_callback);
}

function addFaq()
{
    $('edit_faq_section').style.display="none";
    callAJAX('xoad_handler','addFaq', $H({}),addFaq_callback);
}

function addFaq_callback(result)
{
    if (result=="OK")
	{
		$('edit_faq_section').style.display="";
	}
	else
	{
		alert(result);
	}
}

function saveFaq_callback()
{
    $('edit_faq_section').style.display="none";
}

function deleteFaq(faq_id)
{
    var sure = confirm('Are you sure to delete this question?');
	if (sure) 
	{
        $('edit_faq_section').style.display="none";
        callAJAX('xoad_handler','deleteFaq', $H({faq_id: faq_id}), deleteFaq_callback);	
	} 
}

function deleteFaq_callback(result)
{
    if (result !="OK")
    {
        alert(result);
    }
}

function answerQuestion(question_id)
{
    callAJAX('xoad_handler','answerQuestion', $H({question_id: question_id}), answerQuestion_callback);	
}

function answerQuestion_callback(result)
{
    if (result !="OK")
    {
        alert(result);
    }
    else
    {
        $('edit_question_section').style.display="";
    }
}

function deleteQuestion(question_id)
{
    var sure = confirm('Are you sure to delete this question?');
	if (sure) 
	{
        $('edit_question_section').style.display="none";
        callAJAX('xoad_handler','deleteQuestion', $H({question_id: question_id}), deleteQuestion_callback);	
	} 
}

function deleteQuestion_callback(result)
{
    if (result !="OK")
    {
        alert(result);
    }
    else
    {
        $('edit_question_section').style.display="none";
    }
}

function copyQuestion(question_id)
{
    callAJAX('xoad_handler','copyQuestion', $H({question_id: question_id}), copyQuestion_callback);	
}

function copyQuestion_callback(result)
{
    if (result !="OK")
    {
        alert(result);
    }
}

function saveAnswer()
{
    callAJAX('xoad_handler','saveQuestion', $H({form: xoad.html.exportForm('question_edit_form')}),saveQuestion_callback);
}

function saveQuestion_callback(result)
{
    if (result !="OK")
    {
        alert(result);
    }
    else
    {
        $('edit_question_section').style.display="none";
    }
}

function cancelAnswer()
{
    $('edit_question_section').style.display="none";
}

function saveAddLink(p_objForm)
{
	if ( p_objForm.link_name.value == '' ) 
	{
		alert("Please input link name!");
		p_objForm.link_name.focus();
		return false;
	}
	if ( p_objForm.link_title.value == '' ) 
	{
		alert("Please input link title!");
		p_objForm.link_title.focus();
		return false;
	}
	if ( p_objForm.link_url.value == '' ) 
	{
		alert("Please input link url!");
		p_objForm.link_url.focus();
		return false;
	}
	callAJAX('xoad_handler','doaddlink', $H({form: xoad.html.exportForm('link_add_form')}),saveAddLink_callback);
	return false;
}
var saveAddLink_callback = function saveAddLink_callback(results)
{
	if (results !="OK")
	{
			alert(results);
	}
	else
	{
			$('edit_link_section').style.display="none";
			alert("Action successfully!");
	}
}

function addFrmLink()
{
	$('edit_link_section').style.display="";
	callAJAX('xoad_handler','frmaddlink', $H({}));
}

function editLink(link_id)
{
    callAJAX('xoad_handler','editLink', $H({link_id: link_id}),editLink_callback);
}

function editLink_callback(result)
{
    if (result=="OK")
	{
		$('edit_link_section').style.display="";
	}
	else
	{
		alert(result);
	}
}


function saveLink()
{
    callAJAX('xoad_handler','saveLink', $H({form: xoad.html.exportForm('link_edit_form')}),saveLink_callback);
}

function saveLink_callback(result)
{
    if (result !="OK")
    {
        alert(result);
    }
    else
    {
        $('edit_link_section').style.display="none";
    }
}

function cancelLink()
{
    $('edit_link_section').style.display="none";
}

function addPartner()
{
    callAJAX('xoad_handler','addPartner', $H({}),editPartner_callback);
}

function editPartner(partner_id)
{
    callAJAX('xoad_handler','editPartner', $H({partner_id: partner_id}),editPartner_callback);
}

function editPartner_callback(result)
{
    if (result=="OK")
	{
		$('edit_partner_section').style.display="";
	}
	else
	{
		alert(result);
	}
}

function savePartner()
{
    callAJAX('xoad_handler','savePartner', $H({form: xoad.html.exportForm('partner_edit_form')}),savePartner_callback);
}

function savePartner_callback(result)
{
    if (result !="OK")
    {
        alert(result);
    }
    else
    {
        $('edit_partner_section').style.display="none";
    }
}

function cancelPartner()
{
    $('edit_partner_section').style.display="none";
}

function deletePartner(partner_id,partner_title)
{
    var sure = confirm('Are you sure to delete the partner ' + partner_title + ' ?');
	if (sure) 
	{
        $('edit_partner_section').style.display="none";
        callAJAX('xoad_handler','deletePartner', $H({partner_id: partner_id}), deletePartner_callback);	
	} 
}

function deletePartner_callback(result)
{
    if (result !="OK")
    {
        alert(result);
    }
}